{% load static %}


<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
  <script src="{% static 'admin/js/vendor/jquery/jquery.js' %}"></script>
</head>
<body>
{% comment %} success {{ yamlfile }} {% endcomment %}



<form action="" method="post">{% csrf_token %}
  <select id=host_id multiple="multiple" size="10" required>
    {% for host in all_hosts %}
    <option id="host.id" value="{{ host.HostIp }}" >{{ host.hostName }}#{{ host.HostIp }}</option>
    {% endfor %}
  </select>


  <br>
  <hr>
 
  <input type=button id='putcfgfile' value="发布配置文件" class="btn btn-primary">
  <input type=button value="返回" onClick="javascript:history.go(-1);">

</form>

</body>

<script type="text/javascript">
  $("#putcfgfile").click(function(){
    {% comment %} var hostinfo = document.getElementById("host_id").value; {% endcomment %}
    var hostinfo = "";
    $("select[id*=host_id]").find(":selected").each(function () {
      hostinfo = hostinfo + this.text + ",";
    });
    var yamlfile = '{{ yamlfile }}';
    $.ajax({
      type: "POST",
      dataType: "text",
      url: '{% url 'learn1:putymlfile' %}',
      data:{
                "hostinfo": hostinfo,
                "yamlfile": yamlfile
      },
      success: function (result) {
        console.log("data is :" + result)
        alert("执行结果: " + result );
      }


    })

    });
</script>
</html>